﻿<!--
	Copyright (c) 2014 Varian Medical Systems, Inc.

	Permission is hereby granted, free of charge, to any person obtaining a copy 
	of this software and associated documentation files (the "Software"), to deal 
	in the Software without restriction, including without limitation the rights 
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
	copies of the Software, and to permit persons to whom the Software is 
	furnished to do so, subject to the following conditions:

	 The above copyright notice and this permission notice shall be included in 
	 all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
	THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 
	THE SOFTWARE.
-->
<UserControl 
  x:Class="DemoApp.View.SelectedPatientsView"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:scm="clr-namespace:System.ComponentModel;assembly=WindowsBase"
  >
    <UserControl.Resources>
        <CollectionViewSource
      x:Key="PatientGroups" 
      Source="{Binding Path=SelectedPatients}"
      >
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="Sex" />
            </CollectionViewSource.GroupDescriptions>
            <CollectionViewSource.SortDescriptions>
                <!-- 
        Sort descending by IsCompany so that the 'True' values appear first,
        which means that companies will always be listed before people.
        -->
                <scm:SortDescription PropertyName="Sex" Direction="Descending" />
                <scm:SortDescription PropertyName="LastName" Direction="Ascending" />
            </CollectionViewSource.SortDescriptions>
        </CollectionViewSource>

        <GroupStyle x:Key="PatientGroupStyle">
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <TextBlock 
            x:Name="txt" 
            Background="{StaticResource Brush_HeaderBackground}"
            FontWeight="Bold"
            Foreground="White"
            Margin="1"
            Padding="4,2,0,2"
            Text="Unknown" 
            />
                    <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding Path=Name}" Value="Female">
                            <Setter TargetName="txt" Property="Text" Value="Female" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=Name}" Value="Not Stated">
                            <Setter TargetName="txt" Property="Text" Value="Not Stated" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=Name}" Value="Other">
                            <Setter TargetName="txt" Property="Text" Value="Other" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=Name}" Value="Male">
                            <Setter TargetName="txt" Property="Text" Value="Male" />
                        </DataTrigger>

                    </DataTemplate.Triggers>
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
        </GroupStyle>

        <Style x:Key="PatientItemStyle" TargetType="{x:Type ListViewItem}">
            <!-- 
      Stretch the content of each cell so that we can 
      right-align text in the Total Sales column. 
      -->
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <!-- 
      Bind the IsSelected property of a ListViewItem to the 
      IsSelected property of a MPatientViewModel object.
      -->
            <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
            <Style.Triggers>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="ItemsControl.AlternationIndex" Value="1" />
                        <Condition Property="IsSelected" Value="False" />
                        <Condition Property="IsMouseOver" Value="False" />
                    </MultiTrigger.Conditions>
                    <Setter Property="Background" Value="#EEEEEEEE" />
                </MultiTrigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>

    <DockPanel>
        <Grid DockPanel.Dock="Bottom" Margin="0,2,4,2">
            <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" VerticalAlignment="Center">
                <Button Content="Show plans..." Command="{Binding Path=ShowPlansCommand}" />
                
            </StackPanel>
        </Grid>
        <ListView 
      AlternationCount="2" 
      DataContext="{StaticResource PatientGroups}" 
      ItemContainerStyle="{StaticResource PatientItemStyle}"
      ItemsSource="{Binding}"
      >
            <ListView.GroupStyle>
                <StaticResourceExtension 
          ResourceKey="PatientGroupStyle" 
          />
            </ListView.GroupStyle>

            <ListView.View>
                <GridView>
                    <GridViewColumn 
            Header="Last Name" 
            DisplayMemberBinding="{Binding Path=LastName}" 
            />
                    <GridViewColumn 
            Header="First Name" 
            DisplayMemberBinding="{Binding Path=FirstName}" 
            />
                    <GridViewColumn 
            Header="MRN" 
            DisplayMemberBinding="{Binding Path=MRN}" 
            />
                </GridView>
            </ListView.View>
        </ListView>
    </DockPanel>
</UserControl>
